/****************************************************************************
**
** Gump.h
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#ifndef GumpH
#define GumpH
//--------------------------------------------------------------------------
class TGumpObject
{
private:
	GUMP_OBJECT_TYPE m_Type;
	DWORD m_Serial;
	WORD m_Gump;
	WORD m_GumpPressed;
	WORD m_Color;
	short m_Index;
	short m_TextIndex;
	short m_X;
	short m_Y;
	short m_Width;
	short m_Height;
	short m_TextureWidth;
	short m_TextureHeight;
	short m_MaxWidth;
	short m_ToPage;
	string m_Text;
	wstring m_UnicodeText;
	bool m_HaveBackground;
	bool m_Pressable;
	TEXT_TEXTURE_HEADER m_TextTexture;
	TEntryText *m_TextEntry;

public:
	TGumpObject();
	~TGumpObject();
	
	TGumpObject *m_Next;
	
	SETGET(GUMP_OBJECT_TYPE, Type)
	SETGET(DWORD, Serial)
	SETGET(WORD, Gump)
	SETGET(WORD, GumpPressed)
	SETGET(WORD, Color)
	SETGETEX(short, Index)
	SETGETEX(short, TextIndex)
	SETGETEX(short, X)
	SETGETEX(short, Y)
	SETGETEX(short, Width)
	SETGETEX(short, Height)
	SETGET(short, TextureWidth)
	SETGET(short, TextureHeight)
	SETGETEX(short, MaxWidth)
	SETGETEX(short, ToPage)
	SETGET(string, Text)
	SETGET(wstring, UnicodeText)
	SETGET(bool, Pressable)
	SETGET(bool, HaveBackground)

	void CreateTextTexture(BYTE FontNumber, string str, WORD color, float MaxWidth = 0.0f);

	TEXT_TEXTURE_HEADER GetTextTexture() const {return m_TextTexture;}
	void SetHaveScrollbar(bool val) {m_Pressable = val;}
	void SetScrollbarPosition(short val) {m_MaxWidth = val;}

	TEntryText *GetTextEntry() const {return m_TextEntry;}
	bool GetHaveScrollbar() const {return m_Pressable;}
	short GetScrollbarPosition() const {return m_MaxWidth;}

	void AddText(int index, const wchar_t *text);
};
//--------------------------------------------------------------------------
class TGump
{
private:
	GUMP_TYPE m_Type;
	DWORD m_Serial;
	DWORD m_ID;
	DWORD m_ID2;

	short m_Page;
	short m_X;
	short m_Y;
	short m_MiniX;
	short m_MiniY;
	short m_SelectionIndex;
	short m_Count;

	bool m_NoClose;
	bool m_NoMove;
	bool m_Minimized;
	bool m_Transparent;
	bool m_ListCreated;

	string m_Name;
	
	TEntryText *m_TextEntry;

	int DrawSpellGump(bool mode);
	bool OnSpellLeftDoubleClick();
	
public:
	TGump();
	~TGump();

	TGumpObject *m_Items;

	TGump *m_Next;
	TGump *m_Prev;
	
	SETGET(GUMP_TYPE, Type)
	SETGET(DWORD, Serial)
	SETGET(DWORD, ID)
	SETGET(DWORD, ID2)
	SETGETEX(short, SelectionIndex)
	SETGET(bool, NoMove)
	SETGET(bool, NoClose)
	SETGET(bool, Transparent)
	SETGETEX(short, Count)
	SETGET(string, Name)
	SETGETEX(short, Page)
	SETGET(TEntryText*, TextEntry)
	SETGET(bool, ListCreated);
	
	void SetX(short val);
	void SetY(short val);
	void SetMiniX(short val);
	void SetMiniY(short val);
	void SetMinimized(bool val);
	
	short GetX() const;
	short GetY() const;
	short GetMiniX() const;
	short GetMiniY() const;
	bool GetMinimized() const;
	
	void AddItem(TGumpObject *obj);

	int Draw(bool &mode);

	void GenerateFrame();
	
	void OnClose();
	void OnButtonDown();
	void OnButtonUp();
	bool OnLeftDoubleClick();
	void OnMouseWheel(MOUSE_WHEEL_STATE &state);
	void OnCharPress(TGump *gump, WPARAM &wparam, LPARAM &lparam);
	void OnKeyPress(TGump *gump, WPARAM &wparam, LPARAM &lparam);
	
	void SendGumpResponse(int Index);

	void SendMenuResponse(int Index);

	void SendTradingResponse(int mode);
	
	void SendTextEntryDialogResponse(bool mode);
	
	void SendRenameRequest();
	
	void SendSellList();
	
	void SendBuyList();
	
	void SendTipRequest(BYTE flag);
};
//---------------------------------------------------------------------------
#endif